package ArrayList;

import java.util.*;

/**
 * @Author 12629
 * @Description：
 */
public class Test {




    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> row = new ArrayList<>();
        row.add(1);
        ret.add(row);
        //这上面 第一行已经处理完
        //下面 从第2行开始
        for (int i = 1; i < numRows; i++) {

            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);//新的一行的第一个值
            //这里处理中间列
            //上一行
            List<Integer> prevRow =ret.get(i-1);
            for (int j = 1; j < i; j++) {
                //
                int x = prevRow.get(j) + prevRow.get(j-1);
                curRow.add(x);
            }
            curRow.add(1);////新的一行的最后一个值

            ret.add(curRow);
        }
        return ret;
    }

    public static void main7(String[] args) {

    }

    public static void main6(String[] args) {
        List<List<Integer>> ret1 = new ArrayList<>();
        ret1.add(new ArrayList<>());
        ret1.get(0).add(1);

        List<Integer> ret2 = new ArrayList<>();
        ret2.add(1);
        System.out.println(ret2.get(0));
    }



    public static List<Character> func(String str1,String str2) {
        //1、遍历str1这个字符串看当中 是不是存在str2中的字符
        List<Character> list = new ArrayList<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!str2.contains(ch+"")) {
                list.add(ch);
            }

        }
        return list;
    }

    public static void main5(String[] args) {
        String str1 = "welcome to cvte";
        String str2 = "come";
        List<Character> ret = func(str1,str2);
        for(char ch : ret){
            System.out.print(ch);
        }
    }

    public static void main4(String[] args) {
        ArrayList<Integer> list2 = new ArrayList<>();
        list2.add(1);
        list2.add(2);
        list2.add(3);
        list2.add(4);
        list2.add(5);


        for (int i = 0; i < list2.size(); i++) {
            System.out.print(list2.get(i)+" ");
        }
        System.out.println();

        for(Integer x :list2) {
            System.out.print(x+" ");
        }
        System.out.println();

        System.out.println("=================");

        Iterator<Integer> it = list2.iterator();//调用的是重写的创建接口的方法，返回一个接口对象，接口对象传给Iterator，然后它有向上转型还是什么？接口传给接口可以向上转型？它们明明都是同样的接口，又不是继承下的接口，再说接口怎么向上转型的？不应该是子类向父类转吗？然后这个it.hasNext()怎么就获取到当前这个类里面信息的？
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
            it.remove();
        }
        System.out.println();
        System.out.println("=================");

        ListIterator<Integer> listIterator = list2.listIterator();
        while (listIterator.hasNext()) {
            System.out.print(listIterator.next()+" ");
            list2.set();
            list2.add
            list2.previousIndex

        }

        System.out.println();
        System.out.println("=================");
        ListIterator<Integer> listIterator2 = list2.listIterator(list2.size());

        while (listIterator.hasPrevious()) {
            System.out.print(listIterator.previous()+" ");
        }
        System.out.println();


        List<Integer> list3 = list2.subList(1,3);//[1,3)

        list3.set(0,188);
        System.out.println(list3);//一般情况下 能够直接通过sout输出
        // 引用指向对象当中的内容的时候 此时一定重写toString方法

        list2.remove(new Integer(2));
        System.out.println(list2.get(1));
        list2.set(0,99);
        list2.clear();
        System.out.println(list2);
    }


    public static void main(String[] args) {
        ArrayList<Integer> list1 = new ArrayList<>(15);

        ArrayList<Integer> list2 = new ArrayList<>();
        list2.add(10);
        list2.add(0,100);
        System.out.println(list2);



        List<Integer> list233 = new LinkedList<>();
        list233.add(1);
        list233.add(2);
        list233.add(3);
        Collection<Integer> collection = list233;
        List<Integer> list3 = new ArrayList<>(list233);
        List<Integer> list4 = new ArrayList<>(new LinkedList<>());
        //list3.add(1777);//默认是放到数组最后一个位置
        System.out.println(list3);
        System.out.println(list4);



    }

    public static void main2(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
        myArrayList.display();

        myArrayList.remove(1);
        myArrayList.remove(2);
        myArrayList.remove(5);
        //myArrayList.remove(5777);
        /*System.out.println(myArrayList.get(0));
        System.out.println(myArrayList.get(2));
        System.out.println(myArrayList.get(5));*/
        //myArrayList.set(0,9999);
        //myArrayList.add(-9,199);
        //System.out.println(myArrayList.contains(10));
        //System.out.println(myArrayList.indexOf(10));
        myArrayList.clear();

        myArrayList.display();
    }

    public static void main1(String[] args) {
        Object o = new Object() {
            public boolean equals(Object obj) {
                return true;
            }
        };
        System.out.println(o.equals("Fred"));
    }

    public static String func1(String str) {
        //StringBuilder stringBuilder = new StringBuilder();
        String string = "";
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if(!string.contains(ch+"")) {
                string += ch;
            }
        }
        return string;
    }

    public static String func2(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if(stringBuilder.indexOf(ch+"") < 0) {
                stringBuilder.append(ch);
            }
        }

        return stringBuilder.toString();
    }

    public void merge(int A[], int m, int B[], int n) {
        int i = m-1;
        int j = n-1;
        int k = m+n-1;
        while (i >= 0 && j >= 0) {
            if(A[i] > B[j]) {
                A[k] = A[i];
                k--;
                i--;
            }else {
                A[k] = B[j];
                k--;
                j--;
            }
        }
        //到底是谁走完了 把剩下的元素 拷贝到A数组当中
        while (i >= 0) {
            A[k] = A[i];
            k--;
            i--;
        }

        while (j >= 0) {
            A[k] = B[j];
            k--;
            j--;
        }
    }
}
